/*
 *  dna_cloudparam.h -- provide dna-system clouds running parameters information.
 *  It can tell me cloud running parameters structure definition.  
 *
 *  ORIGINAL AUTHOR: Xu Chun (chun.xu@broadlink.com.cn)
 *
 *  Copyright (c) 2016 Broadlink Corporation
 */

#ifndef __DNA_CLOUDPARAM_H
#define __DNA_CLOUDPARAM_H

#include "dna_compiler.h"

/*
*  dna-system clouds common parameters information.
*/
typedef struct dna_cloud_comm_param {
    /* Cloud platform device control mode:
      *  0 - standard binary, 1 - keyvalue, 2 - passthrough
      *  Please refer to dna_cloud_devdata_format_e
      */
    unsigned int mode;
} dna_cloud_comm_param_t;

/*****************************************************************
*                                               Broadlink
******************************************************************/

typedef struct broadlink_noapp_param {
    char url[16];
    char * js;
    unsigned short js_len;
    unsigned short timeout;         /* AP or cloud server connect timeout */
    unsigned int hijack : 1;
} broadlink_noapp_param_t;

typedef DNA_PACKED_START struct broadlink_param {
    dna_cloud_comm_param_t common;
    /* Device default name */
    char name[62];
    unsigned char did[6];
    unsigned char pid[16];
	unsigned char main_server[62];
	unsigned short main_port;
	unsigned char back_server[62];
	unsigned short back_port;
	unsigned char tcp_server[62];
	unsigned short tcp_port;
	unsigned char ap_name[33];
	unsigned char auto_lock_cfg;
    broadlink_noapp_param_t noapp;
} DNA_PACKED_END broadlink_param_t;

/*****************************************************************
*                                               Jdlink
******************************************************************/

typedef DNA_PACKED_START struct joylink_param {
    dna_cloud_comm_param_t common;
    char uuid[7];
	char secret_key[17];
    char location_en;
	char model_code[33];
    char public_key[67];
} DNA_PACKED_END joylink_param_t;

/*****************************************************************
*                                               Wechat
******************************************************************/

typedef DNA_PACKED_START struct wechat_param {
    dna_cloud_comm_param_t common;
    unsigned char public_name[33];
    unsigned char name_len;
    unsigned char device_id[33];		/* get from cloud or psm "device_id" */
    unsigned char id_len;				/* strlen(device_id) if >0 it means has device_id */
    unsigned char product[8];			/* wechat product */
} DNA_PACKED_END wechat_param_t;

/*****************************************************************
*                                               Alink
******************************************************************/

typedef DNA_PACKED_START struct alink_param {
    dna_cloud_comm_param_t common;
    unsigned char env;
    unsigned char name[34];
    unsigned char model[81];
    unsigned char key[21];
    unsigned char secret[41];
    unsigned char debug_key[21];
    unsigned char debug_secret[41];
} DNA_PACKED_END alink_param_t;

/*****************************************************************
*                                             Greecloud
******************************************************************/

typedef DNA_PACKED_START struct gree_param {
    dna_cloud_comm_param_t common;
    char barcode[32];
    char brand[32];
    char catalog[32];
    char mid[32];
    char model[32];
    char series[32];
    char vender[32];
    char version[32];
    /* Define default device name */
    char name[32];
    char firmware_code[32];
} DNA_PACKED_END gree_param_t;

/*****************************************************************
*                                             Suning
******************************************************************/

typedef DNA_PACKED_START struct suning_param {
    dna_cloud_comm_param_t common;
    char version[4];
    char model[17];
    char env;
} DNA_PACKED_END suning_param_t;

/*****************************************************************
*                                             Gome
******************************************************************/

typedef DNA_PACKED_START struct gome_param {
    dna_cloud_comm_param_t common;
    char model_id[13];
    char model_pin[33];
    unsigned short property_cnt;
    unsigned short property_id[32];
} DNA_PACKED_END gome_param_t;

/*****************************************************************
*                     tcl
******************************************************************/

typedef DNA_PACKED_START struct tcl_param {
	char clientType;
	char did[32+1];
	char joinid[24];      /* ID compdevid */
	char joinkey[36];     /* key compdevkey */
	char brand[12];       /* TCL */
	char company[16+1];   /* COMPANY_NAME */
	char category[10+1];  /* AC DEVICE_TYPE */
	char childctp[10+1];  /* DEVICE_SUB_TYPE */
	char deviceType[32+1];/* DEVICE_ENCODE */
	char firmware[4];
	char platform[4];
	char devResource[32]; /* DEVICE_RESOURCE */
} DNA_PACKED_END tcl_param_t;

/*****************************************************************
*                   hilink
******************************************************************/

#ifdef CONFIG_RM4_APP

#define PROPERTY_BUFFER_SIZE            (3 * 1024)
#define HILINK_KEY_LENGTH               (16)
#define HILINK_HEADER_MAGIC		        0xdeadc0de
#define HILINK_HEADER_VERSION	        0x0000
#define HILINK_HEADER_SIZEOF	        sizeof(hilink_header)
#define HILINK_DATA_SVC 		        "svc_id"
#define HILINK_DATA_FLOW 		        "flow"
#define HILINK_DATA_FLOW_GET	        "get"
#define HILINK_DATA_FLOW_SET 	        "set"

typedef struct hilink_header {
	unsigned int magic;
	unsigned short body_len;
	unsigned short payload_len;
	unsigned short checksum;
	unsigned short version;
} hilink_header;

#else

#define PROPERTY_BUFFER_SIZE            1500
#define HILINK_KEY_LENGTH               (25)

#endif

typedef struct hilink_service {
	unsigned char st[HILINK_KEY_LENGTH];             /**<服务类型 (0,32]*/
	unsigned char sid[HILINK_KEY_LENGTH];            /**<服务ID (0,32]*/
	unsigned char count;
	struct {
		unsigned char key[HILINK_KEY_LENGTH];
	} property[0];
} hilink_service_t;

typedef struct hilink_param {
	unsigned char rea_rsa_cipher[513];
	struct	{
		unsigned char prodId[5];          /** å¦‚ä¸‹å‚æ•°åœ¨hilink è®¤è¯è®¾å¤‡åˆ—è¡¨èŽ·å–  <è®¾å¤‡HiLinkè®¤è¯å· (0,4]  å¯¹åº”è¡¨ä¸­ DeviceId */
		unsigned char model[33];		  /** <è®¾å¤‡åž‹å·(0,32]   å¯¹åº”è¡¨ä¸­ DeviceModel*/
		unsigned char dev_t[4];			  /**<è®¾å¤‡ç±»åž‹(0,3]     å¯¹åº”è¡¨ä¸­ DeviceTypeId */
		unsigned char manu[4];			  /**<è®¾å¤‡åˆ¶é€ å•†(0,3]   å¯¹åº”è¡¨ä¸­ ManufacturerId   broadlink "011"*/
		unsigned char hiv[33];			  /**<è®¾å¤‡Hilinkåè®®ç‰ˆæœ¬  ç›®å‰é»˜è®¤ "2.0"*/
		unsigned char ssid_sectype[2];    /**<è®¾å¤‡Hilink è®¾å¤‡å¹¿æ’­ssid åŠ å¯†ç±»åž‹ ç›®å‰é»˜è®¤ "B"*/
		unsigned char manu_name[33]; /* å¯¹åº”è¡¨ä¸­  ManufacturerNameEn*/
		unsigned char device_typeName[33];   /* å¯¹åº”è¡¨ä¸­  DeviceTypeNameEn*/
	} dev_info;
	unsigned char service_num;
	unsigned char service_property[PROPERTY_BUFFER_SIZE];
} DNA_ALIGNED(1) hilink_param_t;

/*****************************************************************
*                   andlink
******************************************************************/

typedef struct andlink_service {
	unsigned int count;
	struct {
		unsigned short index;
		unsigned char  key[30];
	} property[0];
} andlink_service_t;

typedef struct andlink_param {
	unsigned int and_version;		/*andlink config mode*/
	unsigned char device_type[16]; 		/*Must be in the first*/
	unsigned char product_token[32];
	unsigned char andlink_token[32];	/* check gw */
	unsigned char service_property[PROPERTY_BUFFER_SIZE];
} andlink_param_t;

/*****************************************************************
*                   aux cloud
******************************************************************/

typedef DNA_PACKED_START struct auxcloud_param {
    dna_cloud_comm_param_t common;
    unsigned char product_key[33];
    unsigned char product_key_str[33];
	unsigned char http_server[128];
	unsigned short hard_version;
	unsigned short soft_version;
} DNA_PACKED_END auxcloud_param_t;

/*****************************************************************
*                  qqlink cloud
******************************************************************/

typedef DNA_PACKED_START struct qqlink_param {
    unsigned int pid;          /* ºóÌ¨ÉêÇëÉè±¸ºó,²úÉú²úÆ·ID,server public key(·þÎñÆ÷¹«Ô¿)*/ 
    						  /*ºóÌ¨×¢²áÉè±¸Ê±£¬ÐèÒªÊÇqqÌá¹©µÄ¹¤¾ßÉú³Épublic.pem ec_key.pem  public.pem ÉÏ´«µ½·þÎñÆ÷ºóÌ¨*/
    						  /* ec_key.pem ¶Ôsn Ç©ÃûÊ¹ÓÃ*/
	char device_name[32+1]; 
	char serial_number[16+1];  /*16¸ö×Ö·û£¬¿ÉÒÔÊ¹ÓÃmac + 0000 */
	char license[144+1];       /*Ê¹ÓÃec_key.pem  ¶ÔsnÓ¦Éè±¸µÄÇ©Ãû  */
	char client_pub_key[32+1]; /*¸ù¾ÝºóÌ¨ÉêÇëÉè±¸ºó²úÉúµÄserver public key(·þÎñÆ÷¹«Ô¿) Ê¹ÓÃqq Ìá¹©µÄ¹¤¾ßÉú³Épub_key auth_key*/
	char auth_key[16+1];       /*Ã¿Ò»¸öÉè±¸¶¼¿ÉÒÔÉú³ÉÒ»¶Ôpub_key auth_keyÉè±¸ÃÜÔ¿*/
} DNA_PACKED_END qqlink_param_t;

/*****************************************************************
*                  fastcon cloud
******************************************************************/

typedef DNA_PACKED_START struct fastcon_param {
    unsigned int plat_cnt;
    unsigned char bl:1; // 支持FastCon
    unsigned char tm:1; // 支持tmall
    unsigned char jd:1; // 支持京东thunderconfig
	unsigned int vendor_id;
	unsigned int product_id;
    unsigned char uuid[7];
	unsigned char config_mode;	// bl use 0:only link ap 1: only link master 2:both
	unsigned int master_id;
	unsigned char lock_white_list[32]; //自动锁定masterid白名单
	unsigned int autojoin_support:1; // 是否支持 autojoin

	//login param
	unsigned int login_interval; 	//default 300ms
	unsigned int country_type;		// 0:1~13  1:1~11 default:0
	unsigned char login_channel;	// fix channel if 0 ,it means scan login
	unsigned char retry_cnt;		// Number of fixed channel senders
	unsigned char scan_cnt;			// Scanning times
} DNA_PACKED_END fastcon_param_t;

/*****************************************************************
*                  telecom zhejiang cloud
******************************************************************/

typedef DNA_PACKED_START struct telecom_zj_param {
	char name[32];
	char model[32];
	char dev_version[32];
} DNA_PACKED_END telecom_zj_param_t;

/*****************************************************************
*                       Linkkit (alios)
******************************************************************/

typedef DNA_PACKED_START struct linkkit_param {
	char device_name[33];
    char device_secret[65];
	char product_key[21];
	char product_secret[65];
    /* Dummy filed */
    const char * tsl;
    int tsl_len;
} DNA_PACKED_END linkkit_param_t;

/*****************************************************************
*                       baidu
******************************************************************/

typedef struct baidu_param {
	char client_id[62]; 
	char passwd[22];
	/* Dummy filed */
} baidu_param_t;

/*****************************************************************
*                       Elink (CTCC)
******************************************************************/

typedef DNA_PACKED_START struct elink_param {
    unsigned char pin[13];
    unsigned char key[17];
} DNA_PACKED_END elink_param_t;

/*****************************************************************
*                  simplied fastcon cloud
******************************************************************/

typedef DNA_PACKED_START struct 
{
	/*
	 *	mode: 0: master, 1: client
	 */
	unsigned char mode;
	unsigned char mac[6];
	unsigned short devtype;
	/*
	 *	master create package need client secret key
	 */
	int (*master_subdev_info_get)(const unsigned char mac[6], unsigned char **secret_key);
	/*
	 *	master add subdev need client save secret key
	 */
	int (*master_subdev_info_set)(const unsigned char mac[6], const unsigned char secret_key[32]);
	/*
	 *	master control handler callback
	 *	master role will start a task in background, this callback will be called in background task.
	 *	cmd refer to simpfc_ctl_cmd_e
	 */
	int (*master_ctl_handler)(const unsigned int cmd, const unsigned char mac[6], const unsigned short devtype, unsigned char *pbuf, const int len);
	/*
	 * 	master message handler callback.
	 *	master role will start a task in background, this callback will be called in background task.
	 *	user could handle data directly.
	 *	ctltype refer to simpfc_msgtype_e
	 */
	int (*master_msg_handler)(const unsigned int msgtype, const unsigned char mac[6], const unsigned char *pbuf, const int len);
	/*
	 *	client beacon filter callback.
	 *	client role do not has background task.
	 *	some cmd of this callback will be called in system beacon callback.
	 *	user should not handle data directly, but move the data into application task.
	 */
	int (*client_ctl_handler)(const unsigned short cmd, const unsigned char *pbuf, const int len);
} DNA_PACKED_END simpfc_param_t;

#endif

